﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cn.Edwon.Web.Support;
using Cn.Edwon.Web;
using Cn.Cellula.Client;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Cellula.Model.Security;
using Cn.Edwon.Web.Session;
namespace Cn.Cellula.Website.Port {
    public partial class asdf : PageSupport {
        public String LoginProperty = SiteConfig.Sercurity.UserLoginProperty;
        public String SiteBase = ClientHelper.RootUrl;
        protected void Page_Load(object sender, EventArgs e) {
            SupportUtil.DeployBaseURL(Page, Request);
            this.img_Logo.ImageUrl = SiteConfig.BaseInfo.LogoUrl;
            this.lab_SiteTitle.Text = SiteConfig.BaseInfo.SiteName;
            Page.Title = SiteConfig.BaseInfo.SiteName + " 登录";
        }

        protected void btn_Login_Click(object sender, EventArgs e) {
            this.lab_info.Text = "";
            IUserBiz biz = BizFactory.Get<IUserBiz>();
            if (String.IsNullOrEmpty(this.txt_Username.Text)) {
                this.lab_info.Text = "请输入登录帐号";
                return;
            }
            if(String.IsNullOrEmpty(this.txt_Pwd.Text)){
                this.lab_info.Text = "请输入密码";
                return;
            }
            ISessActor sess = new SessActor();
            new LoginHelper().Login(SiteConfig.Sercurity.UserLoginProperty, this.txt_Username.Text, ClientBiz.Md5(this.txt_Pwd.Text), ref sess);
            if (sess != null) {
                if (sess.IsActivated) {//已经激活
                    sess.LastDate = DateTime.Now;
                    sess.LastIP = Request.UserHostAddress;
                    this.Actor = sess;
                    Response.Redirect("../MiniTop/default.aspx");
                    return;
                } else {
                    if (SiteConfig.Sercurity.UserRegCheck == SiteConfig.RegisterCheck.Email) {//未激活状态
                        this.lab_info.Text = "账户尚未激活";
                        return;
                    } else {//其他认为是未审核通过
                        this.lab_info.Text = "账户尚未通过审核";
                        return;
                    }
                }
            } else {
                this.lab_info.Text = TxtDef.User.BadUsernameOrPwd;
                return;
            }
        }
    }
}